import 'package:flutter/material.dart';
import 'package:flutter_cwhisky/common/style/colors.dart';
import 'package:flutter_cwhisky/component/business/good/good_horizontal_view.dart';
import 'package:flutter_cwhisky/component/ink/ink_well_custom.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../../../../component/base/base_state_less_view.dart';
import '../../../../component/text_view.dart';
import 'classify_logic.dart';

/// @author zavier
/// @time 2023/12/22 16:22
/// @des 社区

class ClassifyPage extends BaseStateLessView<ClassifyLogic> {
  const ClassifyPage({super.key});

  @override
  Widget buildContent(BuildContext context) {
    return Scaffold(
      backgroundColor: AppColors.white,
      body: Container(
        padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top),
        child: Row(
          children: [
            Container(
              width: 100.r,
              color: AppColors.colorF5,
              child: GetBuilder<ClassifyLogic>(
                id: 'classifyList',
                builder: (logic) => ListView.builder(
                  padding: EdgeInsets.zero,
                  itemCount: controller.classifyList.length,
                  itemBuilder: (context, index) => _buildClassifyItem(index),
                ),
              ),
            ),
            Expanded(
                child: Container(
              child: Column(
                children: [
                  Container(
                    height: 46.r,
                    color: AppColors.colorF5,
                  ),
                  Expanded(
                      child: GetBuilder<ClassifyLogic>(
                          id: 'GoodList',
                          builder: (logic) => controller.goodList == null
                              ? const SizedBox()
                              : ListView.builder(
                                  padding: EdgeInsets.zero,
                                  itemCount: controller.goodList!.length,
                                  itemBuilder: (context, index) =>
                                      GoodHorizontalComponent(good: controller.goodList![index]))))
                ],
              ),
            ))
          ],
        ),
      ),
    );
  }

  _buildClassifyItem(int index) {
    var item = controller.classifyList[index];
    var active = controller.currentIndex == index;
    return InkWellCustom(
      onTap: (){
        controller.onClickClassify(index);
      },
      child: Container(
        decoration: BoxDecoration(
            color: active ? AppColors.white : AppColors.transparent,
            boxShadow: active
                ? [const BoxShadow(color: Color(0x0f000000), spreadRadius: 8, blurRadius: 8, offset: Offset(0, 2))]
                : []),
        height: 46.r,
        child: Row(
          children: [
            Container(
              width: 4.r,
              color: active ? AppColors.colorF46309 : AppColors.transparent,
            ),
            Expanded(
                child: Center(
              child: TextView(
                text: item.name ?? '',
                maxLines: 1,
                overflow: TextOverflow.ellipsis,
              ),
            ))
          ],
        ),
      ),
    );
  }
}
